package nninn.api.resources;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;


@Path("/inns")
public class InnsResource {
	@Context
	UriInfo uriInfo;
	@Context
	Request request;

	@GET
	@Path("{city}")
	@Produces(MediaType.APPLICATION_JSON)
	public String getInn(@PathParam("city") String city) {
		URL url;
		String xml = "_";
		try {
			url = new URL("http://api.ean.com/ean-services/rs/hotel/v3/list?minorRev=4&cid=55505&apiKey=y9ntyaaadceua98eshxkjpva&customerIpAddress=192.168.1.100&locale=en_US&currencyCode=USD&city=" + 
					city + 
					"&stateCode=PE&countryCode=BR&arrivalDate=12/01/2011&departureDate=12/03/2011&room1=2&numberOfResults=3");
			URLConnection conn = url.openConnection();
			conn.setDoOutput(true);
			OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
			wr.flush();
			
			BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			xml = rd.readLine();
			
		} catch (MalformedURLException ex) {
			System.out.println("Error:" + ex);	
		} catch (IOException e) {
			System.out.println("Error:" + e);
		}
		
		return xml;
	}
}         